<?php
//==============================================
// 代码所有       PHPText.Net
// 代码作者       黄创钦,tine2cx@163.com
// 联系方式       QQ 233944397
// 本代码开源使用，可以随意修改传播，但请保留本版权
// 声明,谢谢合作！
//==============================================


	define("_NavLV_","PROFile");  //定义当前页面下拉菜单等级
	include "_Global.php";

	$action = $_GET["action"];
	if($action == "list" || $action == "")
	{
		$action = "view";
	}

	if(!_UserLogin_ && !_MemberInfoDisply_)
	{
		ShowMegBox("只有注册会员可以查看。",$_SERVER["HTTP_REFERER"],'back');
	}

	$uid    = $_GET["uid"];
	$mbid   = $_GET["mbid"];
	$toname = $_GET["toname"];
	$firid  = $_GET["firid"];

	if($action=="addFir")
	{
		AddFir($firid);
	}

	if($action=="delFir")
	{
		DelFir($firid);
	}

	if($_POST["ProFileEdit"])
	{
		if(!empty($uid))
		{
			//获取用户信息
			$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$uid);
			$Member     = $MemberInfo[0];
			if($Member["帐号"]==$_POST["OldEMail"] && $Member["密码"]==md5($_POST["OldPasswd"]))
			{
				if((empty($_POST["Issues"]) && empty($_POST["Answer"])) || ((!empty($_POST["Issues"]) || !empty($_POST["Answer"])) && $Member["答案"]==md5($_POST["OldAnswer"])))
				{
					//检测是否需要修改油箱
					if(!empty($_POST["EMail"]) && $_POST["EMail"]==$_POST["EMail2"])
					{
						$EMail = $_POST["EMail"];
					}
					else
					{
						$EMail = $Member["帐号"];
					}

					//检测是否需要修改密码
					if(!empty($_POST["Passwd"]) && $_POST["Passwd"]==$_POST["Passwd2"])
					{
						$Passwd = md5($_POST["Passwd"]);
					}
					else
					{
						$Passwd = $Member["密码"];
					}

					//检测是否需要修改问题
					if(!empty($_POST["Issues"]))
					{
						$Issues = $_POST["Issues"];
					}
					else
					{
						$Issues = $Member["问题"];
					}

					//检测是否需要修改答案
					if(!empty($_POST["Answer"]))
					{
						$Answer = md5($_POST["Answer"]);
					}
					else
					{
						$Answer = $Member["答案"];
					}

					$NewMemberInfo = array($EMail,$Passwd,$Member["昵称"],$Member["权限"],$Issues,$Answer,$_POST["Sex"],$_POST["BDate"],$Member["积分"],$Member["等级"],$_POST["HeadIMG"],$_POST["HomePage"],$_POST["Singed"],$_POST["Maxim"],$Member["发帖数"],$Member["好友"],$Member["每日最大信息数"],$Member["发送记录"],$Member["总发送信息"],$Member["总接收信息"],$Member["注册日期"],$Member["此次访问记录"],$Member["上次访问时间"],$Member["上次访问IP"]);
					UpdateMemberInfo($Member["昵称"],$NewMemberInfo);
					ShowMegBox("资料修改成功。",$_SERVER["HTTP_REFERER"],'goto');
				}
				else
				{
					ShowMegBox("输入答案不正确。",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("输入密码不正确。",$_SERVER["HTTP_REFERER"],'back');
			}
		}
		else
		{
			$action = "view";
		}
	}

	if($_POST["SendMBox"])
	{
		if(!empty($uid))
		{
			$MBoxInfo = array($_POST["title"],$_POST["content"],1,_LoginID_.""._LoginName_,GetClinetIP(),date("Y-m-d H:i:s"));
			SendMBoxInfo($_POST["toname"],$MBoxInfo);
		}
		else
		{
			$action=="view";
		}
	}

	if($action=="delmbox")
	{
		DelMBoxInfo($uid,$mbid);
	}

	//检测是否为操作模式
	if($action=="edit" || $action=="mbox" || $action=="viewmbox" || $action=="fir")
	{
		//检测携带用户ID是否正确
		if(!empty($uid))
		{
			//去除查看模式变量
			$PROFileIMG            = "";
			$PROFileName           = "";
			$PROFileJobs           = "";
			$PROFileSex            = "";
			$PROFileLevel          = "";
			$PROFileBDate          = "";
			$PROFileTopic          = "";
			$PROFileIntegral       = "";
			$PROFileMaxim          = "";
			$PROFileREGDate        = "";
			$PROFileHomePage       = "";
			$PROFileSendButton     = "";
			$PROFileFriendsButton  = "";
			$PROFileSigned         = "";
			$PROFileFriends        = "";

			//去除编辑模式模板变量
			$OldHeadIMG            = "";
			$OldEMail              = "";
			$OldSex1               = "";
			$OldSex2               = "";
			$OldSex3               = "";
			$OldBDate              = "";
			$OldMaxim              = "";
			$OldHomePage           = "";
			$OldSinged             = "";
			$OldIssues             = "";
		}
		else
		{
			$action = "view";
		}
	}

	//检测是否为查看模式
	if($action=="view")
	{
		//检测是否携带用户ID,携带则查看用户信息
		if(!empty($uid))
		{
			//获取用户信息
			$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$uid);
			if($MemberInfo)
			{
				$Member     = $MemberInfo[0];

				//设置头像
				if(empty($Member["头像"]))
				{
					$PROFileIMG = _SkinPath_."/_Images/NOFace.bmp";
				}
				else
				{
					$PROFileIMG = $Member["头像"];
				}

				//设置昵称
				$PROFileName = $Member["昵称"];
				$PROFileID   = $Member[0];

				//设置岗位
				$Skins       = TextDB_SearchData("Skins","目录名",_SkinName_);
				if(!$Skins)
				{
					$Skins = TextDB_SearchData("Skins","目录名",'Default');
				}
				$Jobs        = explode("",$Skins[0]["在线图标".$Member["权限"]]);
				$PROFileJobs = $Jobs[0];

				//设置性别
				if($Member["性别"]==0)
				{
					$seximg = "Unknown.gif";
					$sex    = "保密";
				}
				elseif($Member["性别"]==1)
				{
					$seximg = "Boy.gif";
					$sex    = "男生";
				}
				elseif($Member["性别"]==2)
				{
					$seximg = "Girl.gif";
					$sex    = "女生";
				}

				$PROFileSex    = $sex;
				$PROFileSexIMG = $seximg;

				//设置各项属性
				$PROFileLevel    = $Member["等级"];
				$PROFileBDate    = $Member["生日"];
				$PROFileTopic    = $Member["发帖数"];
				$PROFileIntegral = $Member["积分"];
				$PROFileMaxim    = $Member["格言"];
				$PROFileREGDate  = date('Y-m-d H:i:s',$Member["注册日期"]);
				$PROFileHomePage = $Member["主页"];

				//判断是否登录
				if(_UserLogin_ and $Member["昵称"]!=_LoginName_)
				{
					$LoginMemberInfo   = TextDB_SearchData("Members","TEXTDB_HID",_LoginID_);
					$LoginMember       = $LoginMemberInfo[0];
					$PROFileSendButton = "";
					if(!strstr($LoginMember["好友"],$Member["昵称"]))
					{
						$PROFileFriendsButton = "";
					}
					else
					{
						$PROFileFriendsButton = "disabled='disabled'";
					}
				}
				else
				{
					$PROFileSendButton    = "disabled='disabled'";
					$PROFileFriendsButton = "disabled='disabled'";
				}

				//检测是否有签名
				if(empty($Member["签名"])){
					$PROFileSigned        = "";
					$PROFileSignedDisplay = "show";
				}else{
					$PROFileSigned        = $Member["签名"];
				}

				//检测是否有好友
				if(!empty($Member["好友"]))
				{
					$FirInfo = explode(",",$Member["好友"]);
					foreach($FirInfo as $Fir)
					{
						$Info = explode("",$Fir);
						$PROFileFriends[$FirID]["ID"]   = $Info[0];
						$PROFileFriends[$FirID]["Name"] = $Info[1];
					}
				}
			}
			else
			{
				$NOInfo = 'show';
			}

			//关闭会员列表，显示用户信息
			$PROFileInfoDisplay = "show";

			//去除编辑模式模板变量
			$OldHeadIMG  = "";
			$OldEMail    = "";
			$OldSex1     = "";
			$OldSex2     = "";
			$OldSex3     = "";
			$OldBDate    = "";
			$OldMaxim    = "";
			$OldHomePage = "";
			$OldSinged   = "";
			$OldIssues   = "";
			//结束用户ID寻找
		}
		else //如果没有携带用户ID
		{
			$PROFileIMG            = "";
			$PROFileName           = "";
			$PROFileJobs           = "";
			$PROFileSex            = "";
			$PROFileLevel          = "";
			$PROFileBDate          = "";
			$PROFileTopic          = "";
			$PROFileIntegral       = "";
			$PROFileMaxim          = "";
			$PROFileREGDate        = "";
			$PROFileHomePage       = "";
			$PROFileSendButton     = "";
			$PROFileFriendsButton  = "";
			$PROFileSigned         = "";
			$PROFileFriends        = "";

			//去除编辑模式模板变量
			$OldHeadIMG            = "";
			$OldEMail              = "";
			$OldSex1               = "";
			$OldSex2               = "";
			$OldSex3               = "";
			$OldBDate              = "";
			$OldMaxim              = "";
			$OldHomePage           = "";
			$OldSinged             = "";
			$OldIssues             = "";

			//显示会员列表，关闭用户信息
			$PROFileListDisplay    = "show";

			//获取用户信息
			$MemberInfo = TextDB_SearchData("Members");

			//获取列表信息
			for($MemberID = 0; $MemberID < sizeof($MemberInfo); $MemberID++)
			{
				$Member = $MemberInfo[$MemberID];

				//设置岗位
				$PROFileList[$MemberID]["ALT_Jobs"]   = $OnlineGroup[$Member["权限"]][0];
				$PROFileList[$MemberID]["TITLE_Jobs"] = $OnlineGroup[$Member["权限"]][1];
				$PROFileList[$MemberID]["IMG_Jobs"]   = $OnlineGroup[$Member["权限"]][2];

				//设置昵称
				$PROFileList[$MemberID]["ID"]   = $Member[0];
				$PROFileList[$MemberID]["Name"] = $Member["昵称"];

				//设置性别
				if($Member["性别"]==0)
				{
					$seximg = "Unknown.gif";
					$sex    = "保密";
				}
				elseif($Member["性别"]==1)
				{
					$seximg = "Boy.gif";
					$sex    = "男生";
				}
				elseif($Member["性别"]==2)
				{
					$seximg = "Girl.gif";
					$sex    = "女生";
				}
				$PROFileList[$MemberID]["Sex"]    = $sex;
				$PROFileList[$MemberID]["SexIMG"] = $seximg;

				//设置出生日期
				$PROFileList[$MemberID]["BDate"] = $Member["生日"];

				//判断是否登录
				if(_UserLogin_ and $Member["昵称"]!= _LoginName_)
				{

					$LoginMemberInfo = TextDB_SearchData("Members","TEXTDB_HID",_LoginID_);
					$LoginMember     = $LoginMemberInfo[0];

					$PROFileList[$MemberID]["SendButton"] = "";
					if(!strstr($LoginMember["好友"],$Member["昵称"]))
					{
						$PROFileList[$MemberID]["FriendsButton"] = "";
					}
					else
					{
						$PROFileList[$MemberID]["FriendsButton"] = "disabled='disabled'";
					}
				}
				else
				{
					$PROFileList[$MemberID]["SendButton"]    = "disabled='disabled'";
					$PROFileList[$MemberID]["FriendsButton"] = "disabled='disabled'";
				}
			}
		}
	}

	if($action=="edit")
	{
		//显示修改面板，关闭信箱面板
		$PROFileEditDisplay = "show";

		//获取用户信息
		$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$uid);
		$Member     = $MemberInfo[0];

		$OldHeadIMG = $Member["头像"];
		$OldEMail   = $Member["帐号"];

		//设置性别
		if($Member["性别"]==0)
		{
			$OldSex3 = "checked='checked'";
		}
		elseif($Member["性别"]==1)
		{
			$OldSex1 = "checked='checked'";
		}
		elseif($Member["性别"]==2)
		{
			$OldSex2 = "checked='checked'";
		}

		//设置各项属性
		$OldBDate    = $Member["生日"];
		$OldMaxim    = $Member["格言"];
		$OldHomePage = $Member["主页"];
		$OldSinged   = $Member["签名"];
		$OldIssues   = $Member["问题"];
	}

	if($action=="mbox")
	{
		//关闭修改面板，显示信箱面板
		$PROFileMBoxDisplay  = "show";
		$PROFileNMBoxDisplay = "show";

		//获取用户信息
		$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$uid);
		$Member     = $MemberInfo[0];

		$Num        = explode("",$Member["发送记录"]);
		$MBoxDayNum = $Member["每日最大信息数"]-$Num[0];

		if(!empty($Member["好友"]))
		{
			$FirInfo = explode(",",$Member["好友"]);
			foreach($FirInfo as $K=>$Fir)
			{
				$Info = explode("",$Fir);
				//设置性别
				if(CheckMemberSex($Info[1])==0)
				{
					$seximg = "Unknown.gif";
				}
				elseif(CheckMemberSex($Info[1])==1)
				{
					$seximg = "Boy.gif";
				}
				elseif(CheckMemberSex($Info[1])==2)
				{
					$seximg = "Girl.gif";
				}
				$Firs[$K]["SexIMG"] = $seximg;
				$Firs[$K]["Jobs"]   = $OnlineGroup[CheckMemberJobs($Info[1])][0];
				$Firs[$K]["Name"]   = $Info[1];
			}
			unset($FirInfo);
		}

		//获取用户信息内容
		$MBoxInfo = TextDB_SearchData("MBox_M".$Member[0]);
		if($MBoxInfo)
		{
			foreach($MBoxInfo as $MBID=>$MBInfo)
			{
				//获取信息状态
				if($MBInfo["状态"])
				{
					$MBox[$MBID]["Sta"]      = "NewMBox.gif";
					$MBox[$MBID]["StaAlt"]   = "新";
					$MBox[$MBID]["StaTitle"] = "未读信息";
				}
				else
				{
					$MBox[$MBID]["Sta"]      = "OldMBox.gif";
					$MBox[$MBID]["StaAlt"]   = "旧";
					$MBox[$MBID]["StaTitle"] = "已读信息";
				}

				//获取信息属性
				$MBox[$MBID]["ID"] = $MBInfo[0];

				$SendName=explode("",$MBInfo["SID发送人"]);
				if($SendName[0])
				{
					$MBox[$MBID]["SendUrl"]  = "profile.php?action=view&uid=".$SendName[0];
					$MBox[$MBID]["SendName"] = $SendName[1];
				}
				else
				{
					$MBox[$MBID]["SendUrl"]  = "javascript:;";
					$MBox[$MBID]["SendName"] = "系统信息";
				}

				$MBox[$MBID]["Title"] = $MBInfo["标题"];
				$MBox[$MBID]["Date"]  = $MBInfo["创建时间"];
			}
		}

		if(empty($toname))
		{
			$ToName = "";
		}
		else
		{
			$ToName = $toname;
		}
	}

	if($action=="viewmbox")
	{
		//关闭修改面板，显示信箱面板
		$PROFileNMBoxDisplay = "show";
		$PROFileVMBoxDisplay = "show";

		if(empty($toname))
		{
			$ToName = "";
		}
		else
		{
			$ToName = $toname;
		}

		//获取用户信息
		$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$uid);
		$Member     = $MemberInfo[0];

		$Num        = explode("",$Member["发送记录"]);
		$MBoxDayNum = $Member["每日最大信息数"]-$Num[0];

		if(!empty($Member["好友"]))
		{
			$FirInfo = explode(",",$Member["好友"]);
			foreach($FirInfo as $K=>$Fir)
			{
				$Info = explode("",$Fir);
				//设置性别
				if(CheckMemberSex($Info[1])==0)
				{
					$seximg = "Unknown.gif";
				}
				elseif(CheckMemberSex($Info[1])==1)
				{
					$seximg = "Boy.gif";
				}
				elseif(CheckMemberSex($Info[1])==2)
				{
					$seximg = "Girl.gif";
				}
				$Firs[$K]["SexIMG"] = $seximg;
				$Firs[$K]["Jobs"]   = $OnlineGroup[CheckMemberJobs($Info[1])][0];
				$Firs[$K]["Name"]   = $Info[1];
			}
			unset($FirInfo);
		}

		//获取用户信息内容
		$MBoxInfo = TextDB_SearchData("MBox_M".$Member[0],"TEXTDB_HID",$mbid);
		$MBoxC    = $MBoxInfo[0];

		//获取信息属性
		$MBoxID   = $MBox[0];

		$SendName=explode("",$MBox["SID发送人"]);
		if($SendName[0])
		{
			$MBoxSendUrl  = "profile.php?action=view&uid=".$SendName[0];
			$MBoxSendName = $SendName[1];
		}
		else
		{
			$MBoxSendUrl  = "javascript:;";
			$MBoxSendName = "系统信息";
		}

		$MBoxTitle   = $MBox["标题"];
		$MBoxDate    = $MBox["创建时间"];
		$MBoxContent = $MBox["内容"];

		TextDB_ChangeData("MBox_M".$Member[0],"TEXTDB_HID",$mbid,"状态",0);
	}

	if($action=="fir")
	{
		//设置查看好友状态
		$PROFileFirDisplay = "show";

		//获取用户信息
		$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$uid);
		$Member     = $MemberInfo[0];

		if(!empty($Member["好友"]))
		{
			$FirInfo       = explode(",",$Member["好友"]);
			$PROFileFirNum = sizeof($FirInfo);
			$FirSize       = sizeof($FirInfo);
			$ProFileFirRow = 0;
			$ProFileFirID  = 0;

			foreach($FirInfo as $Fir)
			{
				$Info = explode("",$Fir);

				//设置性别
				if(CheckMemberSex($Info[1])==0)
				{
					$seximg = "Unknown.gif";
					$sex    = "保密";
				}
				elseif(CheckMemberSex($Info[1])==1)
				{
					$seximg = "Boy.gif";
					$sex    = "男生";
				}
				elseif(CheckMemberSex($Info[1])==2)
				{
					$seximg = "Girl.gif";
					$sex    = "女生";
				}

				$ProFileFirID++;

				//如果用户1
				if($ProFileFirID==1)
				{
					$PROFileFir[$ProFileFirRow]["LeftDisplay"]   = "show";
					$PROFileFir[$ProFileFirRow]["LeftName"]      = $Info[1];
					$PROFileFir[$ProFileFirRow]["LeftID"]        = $Info[0];
					$PROFileFir[$ProFileFirRow]["LeftSexIMG"]    = $seximg;
					$PROFileFir[$ProFileFirRow]["LeftSex"]       = $sex;
					$PROFileFir[$ProFileFirRow]["LeftJobs"]      = $OnlineGroup[CheckMemberJobs($Info[1])][0];
					$PROFileFir[$ProFileFirRow]["LeftREGDate"]   = date("Y-m-d",GetMemberREGDate($Info[1]));
				}
				//如果用户2
				if($ProFileFirID==2)
				{
					$PROFileFir[$ProFileFirRow]["CenterDisplay"] = "show";
					$PROFileFir[$ProFileFirRow]["CenterName"]    = $Info[1];
					$PROFileFir[$ProFileFirRow]["CenterID"]      = $Info[0];
					$PROFileFir[$ProFileFirRow]["CenterSexIMG"]  = $seximg;
					$PROFileFir[$ProFileFirRow]["CenterSex"]     = $sex;
					$PROFileFir[$ProFileFirRow]["CenterJobs"]    = $OnlineGroup[CheckMemberJobs($Info[1])][0];
					$PROFileFir[$ProFileFirRow]["CenterREGDate"] = date("Y-m-d",GetMemberREGDate($Info[1]));
				}
				//如果用户3
				if($ProFileFirID==3)
				{
					$PROFileFir[$ProFileFirRow]["RightDisplay"]  = "show";
					$PROFileFir[$ProFileFirRow]["RightName"]     = $Info[1];
					$PROFileFir[$ProFileFirRow]["RightID"]       = $Info[0];
					$PROFileFir[$ProFileFirRow]["RightSexIMG"]   = $seximg;
					$PROFileFir[$ProFileFirRow]["RightSex"]      = $sex;
					$PROFileFir[$ProFileFirRow]["RightJobs"]     = $OnlineGroup[CheckMemberJobs($Info[1])][0];
					$PROFileFir[$ProFileFirRow]["RightREGDate"]  = date("Y-m-d",GetMemberREGDate($Info[1]));
					$ProFileFirID=0;
					$ProFileFirRow++;
				}

				if($ProFileFirRow>2)
				{
					break;
				}
			}

			if($ProFileFirID && $ProFileFirID<4)
			{
				$ProFileFirID++;

				for(;$ProFileFirID<4;$ProFileFirID++)
				{
					if($ProFileFirID==1)
					{
						$PROFileFir[$ProFileFirRow]["LeftName"]      = "";
						$PROFileFir[$ProFileFirRow]["LeftID"]        = "";
						$PROFileFir[$ProFileFirRow]["LeftSexIMG"]    = "";
						$PROFileFir[$ProFileFirRow]["LeftSex"]       = "";
						$PROFileFir[$ProFileFirRow]["LeftJobs"]      = "";
						$PROFileFir[$ProFileFirRow]["LeftREGDate"]   = "";
					}
					if($ProFileFirID==2)
					{
						$PROFileFir[$ProFileFirRow]["CenterName"]    = "";
						$PROFileFir[$ProFileFirRow]["CenterID"]      = "";
						$PROFileFir[$ProFileFirRow]["CenterSexIMG"]  = "";
						$PROFileFir[$ProFileFirRow]["CenterSex"]     = "";
						$PROFileFir[$ProFileFirRow]["CenterJobs"]    = "";
						$PROFileFir[$ProFileFirRow]["CenterREGDate"] = "";
					}
					if($ProFileFirID==3)
					{
						$PROFileFir[$ProFileFirRow]["RightName"]     = "";
						$PROFileFir[$ProFileFirRow]["RightID"]       = "";
						$PROFileFir[$ProFileFirRow]["RightSexIMG"]   = "";
						$PROFileFir[$ProFileFirRow]["RightSex"]      = "";
						$PROFileFir[$ProFileFirRow]["RightJobs"]     = "";
						$PROFileFir[$ProFileFirRow]["RightREGDate"]  = "";
					}
				}
			}
		}
		else
		{
			$PROFileFirNum = 0;
		}
	}

	if(($action=="edit" or $action=="mbox" or $action=="viewmbox") && (!_UserLogin_))
	{
		ShowMegBox("请先登陆！",$_SERVER["HTTP_REFERER"],'back');
	}

	$SkinDir = $SkinDir;

	//检测是否是自己
	if($Member["昵称"]==_LoginName_)
	{
		$PROFileSelect = "show";
	}

	if(CheckForumAdmin() and $uid!=_LoginID_)
	{
		$ForumAdminModeDisplay = "show";
	}

	$MemberID = $uid;
	$LoginID  = _LoginID_;

	_Header(_ForumTitle_);

	if(isset($PROFileListDisplay) || isset($PROFileInfoDisplay))
	{
		require GetMod('PROFileView');
	}
	else
	{
		require GetMod('PROFileAction');
	}

	_Footer();
?>